﻿using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace Test
{
  /// <summary>
  /// Description of ReferencedAssemblyTests.
  /// </summary>
  [TestFixture]
  public class ReferencedAssemblyTests : AssemblyTests
  {
    private static ProgramFullName = "TestAssembly.Program";
    private static NestedFullName = "TestAssembly.Program.Nested";


    [Test]
    public TestAllTypes() : void
    {
      Assert.IsTrue(CommonProject.LoadedAssemblies.First().AllTypes.Any(t => t.FullName == ProgramFullName), "Assembly does not contains type 'Program'");
      Assert.IsTrue(CommonProject.LoadedAssemblies.First().AllTypes.Any(t => t.FullName == NestedFullName), "Assembly does not contains type 'Nested'");

      def type1 = CommonProject.LoadedAssemblies.First().AllTypes.First(t => t.FullName == NestedFullName);
      def type2 = CommonProject.LoadedAssemblies.First().AllTypes.First(t => t.FullName == NestedFullName);
      Assert.AreEqual(type1, type2, "AllTypes property must be cached");

    }

    [Test]
    public TestTopLevelTypes() : void
    {
      Assert.IsTrue(CommonProject.LoadedAssemblies.First().TopLevelTypes.Any(t => t.FullName == ProgramFullName), "Assembly does not contains top level type 'Program'");
      Assert.IsFalse(CommonProject.LoadedAssemblies.First().TopLevelTypes.Any(t => t.FullName == NestedFullName), "Assembly contains nested type 'Nested' as top level type");

      def type1 = CommonProject.LoadedAssemblies.First().TopLevelTypes.First(t => t.FullName == ProgramFullName);
      def type2 = CommonProject.LoadedAssemblies.First().TopLevelTypes.First(t => t.FullName == ProgramFullName);
      Assert.AreEqual(type1, type2, "TopLevelTypes property must be cached");
    }

    [Test]
    public TestEqualTopLevelAndAllTypes() : void
    {
      def type1 = CommonProject.LoadedAssemblies.First().AllTypes.First(t => t.FullName == ProgramFullName);
      def type2 = CommonProject.LoadedAssemblies.First().TopLevelTypes.First(t => t.FullName == ProgramFullName);

      Assert.AreEqual(type1, type2, "TypeInfo from TopLevelTypes must be equals to corresponding TypeInfo from AllTypes property");
    }

  }
}
